'''
9/24/2013

Basic Script to Bake Animation of Selected Joints.  With help from the guys at Anzovin Studio.

Usage:
Select bindJoints01 (or any Topmost Node that contains the Joint(s) or Joint Hierarchy you want to bake the animation to.
'''

import maya.cmds as cmds
    
def bakeJoints(joints):
    startTime=cmds.playbackOptions(ast=True, q=True)
    endTime=cmds.playbackOptions(aet=True, q=True)

    # The format of the time parameter to bakeResults changed between
    # Maya 2011 and 2012, hence the following:
    if cmds.about(api=True) >= 201200:
        timeParam = (startTime, endTime)
    else:
        timeParam = "%s:%s" % (startTime, endTime)

    cmds.bakeResults(joints, simulation=True,
                   sampleBy=1, time=timeParam,
                   disableImplicitControl=True, preserveOutsideKeys=True, hierarchy=True,
                   sparseAnimCurveBake=False, removeBakedAttributeFromLayer=False,
                   bakeOnOverrideLayer=False, controlPoints=False, shape=True)
    
	cmds.select(cmds.ls(dag=1, ap=1, sl=1, type="constraint"))
    cmds.delete()
    # Selects and Deletes all constraints in the Hierarchy
	
    print "DONE!"
                   
                   
bkJoints = cmds.ls(dag=1, ap=1, sl=1, type="joint")
#Selects all Joints in the Hierarchy of the selected node

bakeJoints(bkJoints)
#runs bakeJoints on bkJoints


'''
#shelf button:
import AnimBakeSelected
reload(AnimBakeSelected)

Definitions:
(dag) dagObjects
(ap) allPaths
(sl) selection

cmds.select(cmds.ls(dag=1, ap=1, sl=1, type="joint"))
cmds.select(cmds.ls(dag=1, ap=1, sl=1, type="nurbsCurve"))
cmds.select(cmds.ls(dag=1, ap=1, sl=1, type="constraint"))

cmds.select (all=True)
cmds.select (hi=True)
'''


'''
7/31/2013

Basic Script to Bake Animation of Selected Joints.  With help from the guys at Anzovin Studio.

Usage:
Select the Joint(s) or Joint Hierarchy you want to bake the animation to.


import maya.cmds as cmds
    
def bakeJointKeyframes(joints):
    startTime=cmds.playbackOptions(ast=True, q=True)
    endTime=cmds.playbackOptions(aet=True, q=True)

    # The format of the time parameter to bakeResults changed between
    # Maya 2011 and 2012, hence the following:
    if cmds.about(api=True) >= 201200:
        timeParam = (startTime, endTime)
    else:
        timeParam = "%s:%s" % (startTime, endTime)

    cmds.bakeResults(joints, simulation=True,
                   sampleBy=1, time=timeParam,
                   disableImplicitControl=True, preserveOutsideKeys=True, hierarchy=True,
                   sparseAnimCurveBake=False, removeBakedAttributeFromLayer=False,
                   bakeOnOverrideLayer=False, controlPoints=False, shape=True)
                   
selected = cmds.ls(sl=True)

bakeJointKeyframes(selected)
'''